//
//  EFCircleViewController.m
//  insurance
//
//  Created by 王长飞 on 2019/9/26.
//  Copyright © 2019年 王长飞. All rights reserved.
//

#import "InsuranceViewController.h"
#import "ProductDetailController.h"
#import "InsuranceCell.h"
#import "MJRefresh.h"
#import "CategoryFirstModel.h"
#import "CompanyModel.h"
#import "CategorySecondModel.h"
#import "CategoryThirdModel.h"
#import "InsuranceModel.h"


@interface InsuranceViewController ()<UITableViewDataSource,UITableViewDelegate,BaseModelProtocol,UITextFieldDelegate>

@property (nonatomic,strong)UIView *searchBgView ;
@property (nonatomic,strong)UITextField *searchField;
@property (nonatomic,strong)UIView *leftView ;
@property (nonatomic,strong)UIView *rightView ;
@property (nonatomic,strong)UIView *selectView ;
@property (nonatomic,strong)UITableView *tableView ;

@property (nonatomic,strong)CategoryFirstModel *categoryFirstModel ;
@property (nonatomic,strong)NSArray *categoryFirstArray ;
@property (nonatomic,strong)NSString *firstCategoryId ;

@property (nonatomic,strong)CompanyModel *companyModel;
@property (nonatomic,strong)UIView *companyCoverView;
@property (nonatomic,strong)NSArray *companyArray ;
@property (nonatomic,strong)NSString *companyId;

@property (nonatomic,strong)CategorySecondModel *categorySecondModel ;
@property (nonatomic,strong)UIView *categorySecondCoverView;
@property (nonatomic,strong)NSArray *categorySecondArray ;
@property (nonatomic,strong)NSString *secondCategoryId;

@property (nonatomic,strong)CategoryThirdModel *categoryThirdModel ;
@property (nonatomic,strong)NSArray *categoryThirdArray ;
@property (nonatomic,strong)NSMutableArray *thirdCategoryIdList;
@property (nonatomic,strong)UIView *categoryThirdCoverView;

@property (nonatomic,strong)InsuranceModel *dataModel ;
@property (nonatomic,assign)int pageIndex ;
@property (nonatomic,strong)NSMutableArray *dataArray ;

@end

@implementation InsuranceViewController


- (void)initView{
    
    [super initView];
    [self.view addSubview:self.statusOrangeView];
    [self.view addSubview:self.searchBgView];
    [self.view addSubview:self.leftView];
    [self.view addSubview:self.rightView];
    [self.rightView addSubview:self.selectView];
    [self.rightView addSubview:self.tableView];

    [self showHUD];
    [self.categoryFirstModel getCategoryFirstData];
    self.pageIndex = 1;
    [self loadData];
}

- (void)loadData{
    [self.dataModel getDataList:self.companyId firstCategoryId:self.firstCategoryId secondCategoryId:self.secondCategoryId thirdCategoryIdList:self.thirdCategoryIdList title:_searchField.text pageNum:self.pageIndex];
}

- (void)getDataFinish:(BaseModel *)baseModel netError:(NSError *)error{
    
    [self hideHUD];
    
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
//    [self.tableView.mj_footer setHidden:YES];
}

- (void)getDataFinish:(BaseModel *)baseModel netResponse:(BaseResponse *)response{
    if([baseModel isKindOfClass:[CategoryFirstModel class]])
    {
        CategoryFirstResponse *resp = (CategoryFirstResponse *)response;
        NSArray <CategoryFirstData> *resObject = resp.resObject;
        self.categoryFirstArray = resObject;
        [self initLeftView];
        [self.companyModel getCompanyData:@""];
        [self.categorySecondModel getCategorySecondData:@""];
    }
    else if([baseModel isKindOfClass:[CompanyModel class]])
    {
        CompanyResponse *resp = (CompanyResponse *)response;
        NSArray <CompanyData> *resObject = resp.resObject;
        self.companyArray = resObject;
    }
    else if([baseModel isKindOfClass:[CategorySecondModel class]])
    {
        CategorySecondResponse *resp = (CategorySecondResponse *)response;
        NSArray <CategorySecondData> *resObject = resp.resObject;
        self.categorySecondArray = resObject;
    }
    else if([baseModel isKindOfClass:[CategoryThirdModel class]])
    {
        CategoryThirdResponse *resp = (CategoryThirdResponse *)response;
        NSArray <CategoryThirdData> *resObject = resp.resObject;
        self.categoryThirdArray = resObject;
        [self showCategoryThirdDialog];
    }
    else if([baseModel isKindOfClass:[InsuranceModel class]])
    {
        [self hideHUD];

        InsuranceResponse *resp = (InsuranceResponse *)response;
        NSArray<InsuranceDataList> *list = resp.resObject.list;
        if (self.pageIndex == 1){
            [self.dataArray removeAllObjects];
        }
        [self.dataArray addObjectsFromArray:list];
        [self.tableView reloadData];
        
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
        self.tableView.mj_header.hidden = !self.dataArray.count ;
        self.tableView.mj_footer.hidden= resp.resObject.totalPage <= self.pageIndex ;
    }
}

- (void)headerRefresh
{
    self.pageIndex = 1 ;
//    [self.dataArray removeAllObjects];
    [self loadData];
}

- (void)footerRefresh
{
    self.pageIndex++ ;
    [self loadData];
}

- (void)initLeftView{
    for (int i = 0; i < self.categoryFirstArray.count+1; i++) {
        CGFloat height = 36;
        UILabel *categoryNamelab = [[UILabel alloc]initWithFrame:CGRectMake(0, 20+(height+10)*i, self.leftView.width, height)];
        categoryNamelab.textAlignment = NSTextAlignmentCenter;
        categoryNamelab.font = kFontMidden;
        categoryNamelab.textColor = kTitleColor_midden;
        categoryNamelab.tag = i+100;
        [categoryNamelab addTapCallBack:self sel:@selector(categoryFirstNamelabTap:)];
        [self.leftView addSubview:categoryNamelab];
        
        if(i == 0){
            categoryNamelab.text = @"全部";
            categoryNamelab.backgroundColor = UIColorFromRGB1(0xE5B580);
        }else{
            CategoryFirstData *data = self.categoryFirstArray[i-1];
            categoryNamelab.text = data.categoryName;
        }
    }
}

- (void)categoryFirstNamelabTap:(UITapGestureRecognizer *)tap{
    for(UILabel *lab in self.leftView.subviews){
        if(lab.tag == tap.view.tag){
            lab.backgroundColor = UIColorFromRGB1(0xE5B580);
        }else{
            lab.backgroundColor = [UIColor clearColor];
        }
    }
    if(tap.view.tag != 100){
        CategoryFirstData *data = self.categoryFirstArray[tap.view.tag-100-1];
        self.firstCategoryId = data.eid;
    }else{
        self.firstCategoryId = @"";
    }
    [self showHUD];
    [self.companyModel getCompanyData:self.firstCategoryId];
    [self.categorySecondModel getCategorySecondData:self.firstCategoryId];
    self.pageIndex = 1;
    [self loadData];
}

- (void)showCompanyDialog{
    
    UIView *coverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.companyCoverView = coverView ;
    coverView.userInteractionEnabled = YES ;
    coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.51];
    [coverView addTapCallBack:self sel:@selector(companyCoverViewTap)];
    [[UIApplication sharedApplication].keyWindow addSubview:coverView];
    
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(30, 0, SCREEN_WIDTH-60, SCREEN_HEIGHT*0.7)];
    bgView.userInteractionEnabled = YES;
    bgView.backgroundColor = [UIColor whiteColor];
    [bgView setCornerRedius:3];
    [coverView addSubview:bgView];
    
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 30)];
    titleLab.text = @"请选择保险公司";
    titleLab.textColor = kTitleColor_black;
    titleLab.font = kFontBig;
    [bgView addSubview:titleLab];
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 45, bgView.width-20, bgView.height-50)];
    [bgView addSubview:scrollView];
    
    CGFloat height = 36;
    for (int i = 0; i < self.companyArray.count+1; i++) {
        UILabel *companyNamelab = [[UILabel alloc]initWithFrame:CGRectMake(0, height*i, scrollView.width, height)];
        companyNamelab.font = kFontMidden;
        companyNamelab.textColor = kTitleColor_midden;
        companyNamelab.tag = i+100;
        [companyNamelab addTapCallBack:self sel:@selector(companyNamelabTap:)];
        [scrollView addSubview:companyNamelab];
        
        if(i == 0){
            companyNamelab.text = @"全部";
        }else{
            CompanyData *data = self.companyArray[i-1];
            companyNamelab.text = data.insuranceCangbaotuCompanyName;
        }
    }
    CGFloat totalHeight = (self.companyArray.count+1)*height+50;
    if(totalHeight > SCREEN_HEIGHT*0.8){
        bgView.height = SCREEN_HEIGHT*0.8;
        scrollView.height = bgView.height - 45;
        scrollView.contentSize = CGSizeMake(0, (self.companyArray.count+1)*height);
    }else{
        bgView.height = totalHeight;
        scrollView.height = bgView.height - 45;
    }
    bgView.centerY = SCREEN_HEIGHT/2;
}

- (void)companyCoverViewTap{
    [self.companyCoverView removeFromSuperview];
}

- (void)companyNamelabTap:(UITapGestureRecognizer *)tap{
    [self.companyCoverView removeFromSuperview];
    if(tap.view.tag != 100){
        CompanyData *data = self.companyArray[tap.view.tag-100-1];
        self.companyId = data.insuranceCangbaotuCompanyId;
    }else{
        self.companyId = @"";
    }
    self.pageIndex = 1;
    [self loadData];
}

- (void)showCategorySecondDialog{
    
    UIView *coverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.categorySecondCoverView = coverView ;
    coverView.userInteractionEnabled = YES ;
    coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.51];
    [coverView addTapCallBack:self sel:@selector(categorySecondCoverViewTap)];
    [[UIApplication sharedApplication].keyWindow addSubview:coverView];
    
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(30, 0, SCREEN_WIDTH-60, SCREEN_HEIGHT*0.7)];
    bgView.userInteractionEnabled = YES;
    bgView.backgroundColor = [UIColor whiteColor];
    [bgView setCornerRedius:3];
    [coverView addSubview:bgView];
    
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 30)];
    titleLab.text = @"请选择医疗险类型";
    titleLab.textColor = kTitleColor_black;
    titleLab.font = kFontBig;
    [bgView addSubview:titleLab];
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 45, bgView.width-20, bgView.height-50)];
    [bgView addSubview:scrollView];
    
    CGFloat height = 36;
    for (int i = 0; i < self.categorySecondArray.count+1; i++) {
        UILabel *categorySecondNamelab = [[UILabel alloc]initWithFrame:CGRectMake(0, height*i, scrollView.width, height)];
        categorySecondNamelab.font = kFontMidden;
        categorySecondNamelab.textColor = kTitleColor_midden;
        categorySecondNamelab.tag = i+100;
        [categorySecondNamelab addTapCallBack:self sel:@selector(categorySecondlabTap:)];
        [scrollView addSubview:categorySecondNamelab];
        if(i == 0){
            categorySecondNamelab.text = @"全部";
        }else{
            CategorySecondData *data = self.categorySecondArray[i-1];
            categorySecondNamelab.text = data.categoryName;
        }
    }
    CGFloat totalHeight = (self.categorySecondArray.count+1)*height+50;
    if(totalHeight > SCREEN_HEIGHT*0.8){
        bgView.height = SCREEN_HEIGHT*0.8;
        scrollView.height = bgView.height - 45;
        scrollView.contentSize = CGSizeMake(0, (self.categorySecondArray.count+1)*height);
    }else{
        bgView.height = totalHeight;
        scrollView.height = bgView.height - 45;
    }
    bgView.centerY = SCREEN_HEIGHT/2;
}

- (void)categorySecondCoverViewTap{
    [self.categorySecondCoverView removeFromSuperview];
}
- (void)categorySecondlabTap:(UITapGestureRecognizer *)tap{
    [self.categorySecondCoverView removeFromSuperview];
    if(tap.view.tag != 100){
        CategorySecondData *data = self.categorySecondArray[tap.view.tag-100-1];
        self.secondCategoryId = data.eid;
    }else{
        self.secondCategoryId = @"";
    }
    [self.thirdCategoryIdList removeAllObjects];
    if(!ISEMPTY(self.secondCategoryId)){
        [self.categoryThirdCoverView removeFromSuperview];
        //获取三级数据
        [self.categoryThirdModel getCategoryThirdData:self.secondCategoryId];
    }else{
        //全部医疗，不选三级
        self.pageIndex = 1;
        [self loadData];
    }
}

- (void)showCategoryThirdDialog
{
    UIView *coverView = [[UIView alloc]initWithFrame:CGRectMake(_leftView.right, _searchBgView.bottom+40, SCREEN_WIDTH-_leftView.width, SCREEN_HEIGHT-_selectView.bottom)];
    self.categoryThirdCoverView = coverView ;
    coverView.userInteractionEnabled = YES ;
    coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.31];
    [coverView addTapCallBack:self sel:@selector(categoryThirdCoverViewTap)];
    [self.view addSubview:coverView];

    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, coverView.width, 200)];
    bgView.tag = 10;
    bgView.backgroundColor = [UIColor whiteColor];
    [coverView addSubview:bgView];
    
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(12, 10, 60, 30)];
    lab.text = @"请选择";
    lab.tag = 20;
    lab.font = KFontSmall;
    [bgView addSubview:lab];
    
    CGFloat leftMargin = 15;
    CGFloat rowMargin = 10;
    CGFloat verMargin = 6;
    CGFloat left = 15;
    CGFloat top = 50;
    UILabel *prelab;
    CGFloat height = 30;
    CGFloat totalHeight = top+height;
    for (int i = 0; i < self.categoryThirdArray.count; i++) {
        CategoryThirdData *data = self.categoryThirdArray[i];
        float width = [PublicUtils getLabelWidthWithString:data.categoryName font:kFontMimi]+16;
        if(i != 0){
            if(prelab.right+rowMargin > bgView.width){
                left = leftMargin;
                top = prelab.bottom + rowMargin;
            }else{
                if(prelab.right+rowMargin+width > bgView.width){
                    left = leftMargin;
                    top = prelab.bottom + verMargin;
                }else{
                    left = prelab.right+verMargin;
                    top = prelab.top;
                }
            }
            totalHeight = top+height;
        }
        UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(left, top, width, height)];
        lab.text = data.categoryName;
        lab.font = kFontMimi;
        lab.tag = 100+i;
        lab.textColor = kTitleColor_midden;
        lab.textAlignment = NSTextAlignmentCenter;
        lab.backgroundColor = UIColorFromRGB1(0xF0F0F0);
        [lab setCornerRedius:3];
        [lab addTapCallBack:self sel:@selector(thirdCategoryTap:)];
        prelab = lab;
        [bgView addSubview:lab];
    }
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(4, totalHeight+20, bgView.width, 1)];
    line.backgroundColor = kColorDefultBg;
    [bgView addSubview:line];

    UIView *btnView = [[UIView alloc]initWithFrame:CGRectMake(0, line.bottom, bgView.width, 40)];
    [bgView addSubview:btnView];

    UIButton *resetBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, bgView.width/2, btnView.height)];
    [resetBtn setTitle:@"重置" forState:UIControlStateNormal];
    [resetBtn setTitleColor:kTitleColor_midden forState:UIControlStateNormal];
    resetBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [resetBtn addTarget:self action:@selector(resetBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:resetBtn];

    UIButton *sureBtn = [[UIButton alloc]initWithFrame:CGRectMake(resetBtn.right, 0, resetBtn.width, btnView.height)];
    [sureBtn setTitle:@"确定" forState:UIControlStateNormal];
    sureBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [sureBtn addTarget:self action:@selector(sureBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    sureBtn.backgroundColor = UIColorFromRGB1(0xE5B580);
    [btnView addSubview:sureBtn];

    bgView.height = btnView.bottom;
}

- (void)categoryThirdCoverViewTap
{
    [self.categoryThirdCoverView removeFromSuperview];
}

- (void)sureBtnClick:(UIButton *)btn
{
    [self.categoryThirdCoverView removeFromSuperview];
    self.pageIndex = 1;
    [self loadData];
}

- (void)resetBtnClick:(UIButton *)btn
{
    UIView *bgView = [self.categoryThirdCoverView viewWithTag:10];
    for (UILabel *lab in bgView.subviews) {
        if(lab.tag >= 100){
            lab.backgroundColor = UIColorFromRGB1(0xF0F0F0);
        }
    }
    [self.thirdCategoryIdList removeAllObjects];
}

- (void)thirdCategoryTap:(UITapGestureRecognizer *)tap
{
    UILabel *lab = (UILabel *)tap.view;
    CategoryThirdData *data = self.categoryThirdArray[lab.tag-100];
    if([self.thirdCategoryIdList containsObject:data.eid]){
        [self.thirdCategoryIdList removeObject:data.eid];
        lab.backgroundColor = UIColorFromRGB1(0xF0F0F0);
    }else{
        [self.thirdCategoryIdList addObject:data.eid];
        lab.backgroundColor = UIColorFromRGB1(0xFDE0BB);
    }
    NSLog(@"thirdCategoryIdList>>>>>>>%@",self.thirdCategoryIdList);
}

#pragma mark - tableviewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 90;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    InsuranceCell *cell = [InsuranceCell cellWithTableView:tableView indexPath:indexPath];
    
    InsuranceDataList *model = self.dataArray[indexPath.row];
    cell.model = model;
    cell.index = indexPath.section ;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10.0;
}
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//    return [[UIView alloc] init];
//}
//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
//    return [[UIView alloc] init];
//}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    InsuranceDataList *model = self.dataArray[indexPath.row];
    ProductDetailController *detailVC = [[ProductDetailController alloc]init];
    detailVC.secondMenu = model.eid;
    [self.navigationController pushViewController:detailVC animated:YES];

}

- (void)searchClick{
    self.pageIndex = 1;
    [self loadData];
}

- (UIView *)searchBgView{
    if(nil == _searchBgView){
        
        _searchBgView = [[UIView alloc]initWithFrame:CGRectMake(0, self.statusOrangeView.height, SCREEN_WIDTH, 65)];
        _searchBgView.backgroundColor = [UIColor whiteColor];
        
        UIView *searchFieldBgView = [[UIView alloc]initWithFrame:CGRectMake(15, 25, _searchBgView.width-90, 30)];
        [searchFieldBgView setViewEdgeWithBorderWidth:1 cornerRadius:5 borderColor:kTitleColor_light];
        [_searchBgView addSubview:searchFieldBgView];
        
        UIImageView *searchImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 16, 16)];
        searchImage.image = [UIImage imageNamed:@"search_icon.png"];
        [searchFieldBgView addSubview:searchImage];
        
        UITextField *searchField =[[UITextField alloc] initWithFrame:CGRectMake(searchImage.right+10, 0, searchFieldBgView.width-searchImage.right-10, searchFieldBgView.height)];
        _searchField = searchField;
        searchField.delegate = self;
        searchField.font = KFontSmall;
        searchField.placeholder = @"  搜索";
        searchField.clearButtonMode = UITextFieldViewModeAlways;
        [searchFieldBgView addSubview:searchField];
        
        UILabel *searchLab = [[UILabel alloc] initWithFrame:CGRectMake(searchFieldBgView.right+8, 25, 50, 30)];
        searchLab.text = @"搜索";
        searchLab.textColor = kTitleColor_midden;
        searchLab.font = KFontSmall;
        searchLab.backgroundColor = UIColorFromRGB1(0xfffde0bb);
        [searchLab setCornerRedius:5];
        searchLab.textAlignment = NSTextAlignmentCenter;
        [searchLab addTapCallBack:self sel:@selector(searchClick)];
        [_searchBgView addSubview:searchLab];
    }
    return  _searchBgView;
}

- (UITableView *)tableView
{
    if (nil == _tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, _selectView.bottom, _rightView.width, _rightView.height-_selectView.bottom) style:UITableViewStylePlain];
        _tableView.dataSource = self ;
        _tableView.delegate = self ;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.showsVerticalScrollIndicator = NO ;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
        //        _tableView.mj_footer.hidden = YES ;
    }
    return _tableView ;
}


- (UIView *)leftView{
    if(nil == _leftView){
        _leftView = [[UIView alloc]initWithFrame:CGRectMake(0, _searchBgView.bottom, 80, SCREEN_HEIGHT-KTarBarFullHeight-_searchBgView.bottom)];
        [_leftView setCornerRedius:2];
        _leftView.backgroundColor = UIColorFromRGB1(0xFAEEE1);
    }
    return _leftView;
}

- (UIView *)rightView{
    if(nil == _rightView){
        _rightView = [[UIView alloc]initWithFrame:CGRectMake(_leftView.right, _leftView.top, SCREEN_WIDTH-_leftView.right, _leftView.height)];
        _rightView.backgroundColor = [UIColor whiteColor];
    }
    return _rightView;
}

- (UIView *)selectView{
    if(nil == _selectView){
        _selectView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _rightView.width, 40)];
        
        UIView *companyView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _selectView.width/2, _selectView.height)];
        [companyView addTapCallBack:self sel:@selector(showCompanyDialog)];
        [_selectView addSubview:companyView];
        
        UILabel *companyLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, companyView.height)];
        companyLab.text = @"保司选择";
        companyLab.textColor = kTitleColor_midden;
        companyLab.font = KFontSmall;
        companyLab.width = [PublicUtils getLabelWidthWithString:companyLab.text font:KFontSmall];
        companyLab.centerX = companyView.centerX-8;
        [companyView addSubview:companyLab];
        
        UIImageView *arrowImage = [[UIImageView alloc] initWithFrame:CGRectMake(companyLab.right, 12, 16, 16)];
        arrowImage.image = kImage(@"arrow_down.png");
        [companyView addSubview:arrowImage];
        
        UIView * line = [[UIView alloc] initWithFrame:CGRectMake(companyView.right, 10, 1, 20)];
        line.backgroundColor = UIColorFromRGB1(0xE5B580);
        [_selectView addSubview:line];
    
        UIView *xianView = [[UIView alloc]initWithFrame:CGRectMake(line.right, 0, companyView.width-1, companyView.height)];
        [xianView addTapCallBack:self sel:@selector(showCategorySecondDialog)];
        [_selectView addSubview:xianView];
        
        UILabel *xianLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, xianView.height)];
        xianLab.text = @"医疗险";
        xianLab.textColor = kTitleColor_midden;
        xianLab.font = KFontSmall;
        xianLab.width = [PublicUtils getLabelWidthWithString:xianLab.text font:KFontSmall];
        xianLab.centerX = xianView.width/2-8;
        [xianView addSubview:xianLab];
        
        UIImageView *arrowImg = [[UIImageView alloc] initWithFrame:CGRectMake(xianLab.right, 12, 16, 16)];
        arrowImg.image = kImage(@"arrow_down.png");
        [xianView addSubview:arrowImg];
        
        UIView * bottomline = [[UIView alloc] initWithFrame:CGRectMake(4, 39, _selectView.width-8, 1)];
        bottomline.backgroundColor = UIColorFromRGB1(0xE5B580);
        [_selectView addSubview:bottomline];
    }
    return _selectView;
}

- (CategoryFirstModel *)categoryFirstModel{

    if (nil == _categoryFirstModel) {
        _categoryFirstModel = [[CategoryFirstModel alloc]initWithDelegate:self cache:NO];
    }
    return _categoryFirstModel;
}

- (NSArray *)categoryFirstArray{
    if(nil == _categoryFirstArray){
        _categoryFirstArray = [NSArray array];
    }
    return _categoryFirstArray;
}

- (CompanyModel *)companyModel{

    if (nil == _companyModel) {
        _companyModel = [[CompanyModel alloc]initWithDelegate:self cache:NO];
    }
    return _companyModel;
}

- (NSArray *)companyArray{
    if(nil == _companyArray){
        _companyArray = [NSArray array];
    }
    return _companyArray;
}

- (CategorySecondModel *)categorySecondModel{

    if (nil == _categorySecondModel) {
        _categorySecondModel = [[CategorySecondModel alloc]initWithDelegate:self cache:NO];
    }
    return _categorySecondModel;
}

- (NSArray *)categorySecondArray{
    if(nil == _categorySecondArray){
        _categorySecondArray = [NSArray array];
    }
    return _categorySecondArray;
}

- (CategoryThirdModel *)categoryThirdModel{

    if (nil == _categoryThirdModel) {
        _categoryThirdModel = [[CategoryThirdModel alloc]initWithDelegate:self cache:NO];
    }
    return _categoryThirdModel;
}

- (NSArray *)categoryThirdArray{
    if(nil == _categoryThirdArray){
        _categoryThirdArray = [NSArray array];
    }
    return _categoryThirdArray;
}

- (NSMutableArray *)thirdCategoryIdList{
    if(nil == _thirdCategoryIdList){
        _thirdCategoryIdList = [NSMutableArray array];
    }
    return _thirdCategoryIdList;
}

- (InsuranceModel *)dataModel{

    if (nil == _dataModel) {
        _dataModel = [[InsuranceModel alloc]initWithDelegate:self cache:NO];
    }
    return _dataModel;
}

- (NSMutableArray *)dataArray{
    if(nil == _dataArray){
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
@end
